package com.example.mykotilin.navigation2

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class DonutListViewModel(private val donutDao: DonutDao) : ViewModel() {
    val donuts: LiveData<List<Donut>> = donutDao.getAll(); //获取所有的数据

    //进行删除
    fun delete(donut: Donut) = viewModelScope.launch(Dispatchers.IO) {
        donutDao.delete(donut)
    }
}